Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
How to add files to the "public folder" in vue 2?

I have a project made in vue.js 2. However there is no public folder; instead, there is a folder named static where you can put files that will be put in the folder /dist/static after you build the staff.

Meanwhile, I need to add a _redirects file to the root of /dist after building, for Netlify integration. However, if I put the file in the root of the project, after building it is ignored. I know that I need to manage something in the config where I have this code:

build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }

I found vue 2 documentation for this rather confuse. The only thing I need is that my new file _redirects gets included in dist folder after building.

Thanks beforehand for the help.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found the way to do it.

My project uses Webpack with the plugin copy-wepback-plugin. In the documentation of the plugin there is information how to copy files from any path to any path into dist folder after building.

In my case, I added some code in webpack.prod.config.js as shown:

// copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        ignore: ['.*']
      },
      { from: path.resolve(__dirname, '../public'), 
        to: config.build.assetsRoot, 
        ignore: ['.*'] }
    ])

So anything that I put in public folder goes copied to root when building.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!